<!DOCTYPE html>
<html>
<head>
	<title>test</title>
</head>
<body>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<input type="button" value="test_get" onclick="test_get()" />
<input type="button" value="test_create" onclick="test_create()" />
<input type="button" value="test_update" onclick="test_update()" />
<input type="button" value="test_delete" onclick="test_delete()" />
<input type="button" value="test_apply_delivery" onclick="test_apply_delivery()" />
<input type="button" value="test_delivery" onclick="test_delivery()" />
<input type="button" value="test_apply_update" onclick="test_apply_update()" />
<script>
    function test_get() {
        $.ajax({
            type: "GET",
            url: "/v1/sp",
            params: {"typeId": 1},
            success: function (data) {
               alert(data)
            }
        })
    }

    function test_create() {
        $.ajax({
            type: "POST",
            url: "/v1/sp?sessionId=12345678",
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({
                name: "摄像机",
                typeId: 1,
                typeName: "监控",
                equipmentTypeId: 12,
                equipmentTypeName: "照相设备",
                moduleNo: "JVC TK-C925EK",
                maxSKU: 10000,
                minSKU: 100,
                referencePrice: 102.34,
                Unit: "台",
                Remarks: "1",
                CodeBar: "1231233992772",
                Attrs: {"Id": 1, "ContactInfo": {"email1": "xx@yy.com", "phone1": "2223334444"}}
            }),
            success: function (data) {
               alert(data)
            }
        })
    }

    function test_update() {
        $.ajax({
            type: "PUT",
            url: "/v1/sp/36?sessionId=12345678",
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({
                name: "test",
                typeId: 2,
                typeName: "监控1",
                equipmentTypeId: 12,
                equipmentTypeName: "照相设备",
                moduleNo: "JVC TK-C925EK",
                maxSKU: 10000,
                minSKU: 100,
                code: "BJ_SXJ_001",
                referencePrice: 120,
                Unit: "台",
                CodeBar: "1231233992772",
                Remarks: "1",
                Attrs: {"Id": 2, "ContactInfo": {"email1": "xx@yy.com", "phone1": "2223334444"}}
            }),
            success: function (data) {
               alert(data)
            }
        })
    }

    function test_delete() {
        $.ajax({
            type: "DELETE",
            url: "/v1/sp/21",
            success: function (data) {
               alert(data)
            }
        })
    }

    function test_delivery() {
        $.ajax({
            type: "POST",
            url: "/v1/delivery?sessionId=-38820022986418023895861c91a5da42c26a3f10451",
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({
                DeliveryTime: 1479230685000,
                SpareLocationId: 1,
                SpareLocationName: '仓库1',
                OrderType: 0,   
                ApplyOrderCode: "CKSQBH_1483074665",
                ApplyUserId: "1",
                ApplyUserName: "meson",
                ApplyDepartmentId: "1",
                ApplyDepartmentName: '后勤部',
                AuditUserId: "1",
                AuditUserName: "meson",
                LocationAdminUserId: "1",
                LocationAdminUserName: "meson",
                TotalAmount: 2000,
                Remarks: "测试出库",
                Items: [
                    {
                        OrderIndex: 0,
                        SparePartId: 2,
                        SparePartName: '摄像机',
                        // count: 2,
                        Unit: 1,
                        UnitName: "台",
                        Price: 10,
                        Attrs: {"deliveryItemDetail": [
                            {
                                godownEntryCode:"1",
                                count:1
                            },
                            {
                                godownEntryCode:"2",
                                count:1
                            }
                        ]}
                    },
                    {
                        OrderIndex: 0,
                        SparePartId: 1,
                        SparePartName: '摄像机1',
                        // count: 2,
                        Unit: 1,
                        UnitName: "台",
                        Price: 10,
                        Attrs: {"deliveryItemDetail": [
                            {
                                godownEntryCode:"1",
                                count:1
                            },
                            {
                                godownEntryCode:"2",
                                count:1
                            }
                        ]}
                    },
                ],
                attrs: {}
            }),
            success: function (data) {
               alert(data)
            }
        })
    }
    function test_apply_delivery() {
        $.ajax({
            type: "POST",
            url: "/v1/adelivery?sessionId=-38820022986418023895861c91a5da42c26a3f10451",
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({
                DeliveryApplyTime: 1482407774000,
                AssetCode: "ZC001",
                AssetName: "摄像机",
                AssetType: "1",
                AssetTypeName: "摄像机",
                JobCode: "GD001",
                ApplyUserId: "1",
                ApplyUserName: "meson",
                ApplyDepartmentId: "1",
                ApplyDepartmentName: '后勤部',
                AuditUserId: "1",
                AuditUserName: "meson",
                TroubleDescription: "设备损坏",
                LocationAdminUserName: "meson",
                TotalAmount: 2000,
                Remarks: "测试出库",
                Status: 0,
                Attrs: {},
                SpareLocationId: 1,
                SpareLocationName: '仓库1',
                Items: [
                    {
                        OrderIndex: 0,
                        SparePartId: 2,

                        SparePartName: '摄像机',
                        Count: 2
                    },
                    {
                        OrderIndex: 0,
                        SparePartId: 1,
                        SparePartName: '摄像机1',
                        Count: 2
                    },
                ]
            }),
            success: function (data) {
               alert(data)
            }
        })
    }

    function test_apply_update() {
        $.ajax({
            type: "PUT",
            url: "/v1/adelivery/1?sessionId=-38820022986418023895861c91a5da42c26a3f10451",
            dataType: "json",
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({
              "Id": 1,
              "Remarks": "测试出库2",
              "SpareLocationId": 2,
              "SpareLocationName": "仓库2",
              "Items": [
                  {
                      "Id": 1,
                      "OrderIndex": 1,
                      "SparePartId": 21,
                      "SparePartName": "摄像机21",
                      "Count": 2
                  },
                  {
                      "Id": 2,
                      "OrderIndex": 2,
                      "SparePartId": 11,
                      "SparePartName": "摄像机11",
                      "Count": 2
                  }
              ]
            }),
            success: function (data) {
               alert(data)
            }
        })
    }
</script>
</body>
</html>